﻿/// <reference path="jquery-1.5.1-vsdoc.js" />

// PageMethods Oluşturuluyor...

var PageMethods = function () { };

  // Xml Http Request için...
  PageMethods.PleaseWaitStr = "Please Wait...";
  PageMethods.http_request = new Object();
  PageMethods.timeOutID = 0;

  // Browser detection with Regular Expression...
  var useragent = navigator.userAgent.toLowerCase();
  PageMethods.browserVersion = (useragent.match(/.+(?:me|ox|on|rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1];

  PageMethods.isOpera = /opera/i.test(useragent);
  PageMethods.isIE = (/msie/i.test(useragent) && !PageMethods.isOpera);
  PageMethods.isMozilla = /firefox/i.test(useragent);
  PageMethods.isChrome = /chrome/i.test(useragent);
  PageMethods.isSafari = (/safari/i.test(useragent) && !PageMethods.isChrome);
  // IE
  PageMethods.isIE5 = (PageMethods.isIE && (!PageMethods.isOpera) && (parseInt(PageMethods.browserVersion) == 5));
  PageMethods.isIE6 = (PageMethods.isIE && (!PageMethods.isOpera) && (parseInt(PageMethods.browserVersion) == 6));
  PageMethods.isIE7 = (PageMethods.isIE && (!PageMethods.isOpera) && (parseInt(PageMethods.browserVersion) == 7));
  PageMethods.isIE8 = (PageMethods.isIE && (!PageMethods.isOpera) && (parseInt(PageMethods.browserVersion) == 8));
  PageMethods.isIE9 = (PageMethods.isIE && (!PageMethods.isOpera) && (parseInt(PageMethods.browserVersion) == 9));
  PageMethods.isIE10 = (PageMethods.isIE && (!PageMethods.isOpera) && (parseInt(PageMethods.browserVersion) == 10));
  // IE Versiyonunu verir.
  PageMethods.ieVersion = (!PageMethods.isIE) ? null : parseInt(PageMethods.browserVersion);

  // Method Type => POST or GET ?
  PageMethods.formMethodType = "POST";

  // Ajax Timeout Süresi...  Default => 5000 milisecond = 5sn. 
  PageMethods.timeOutDuration = 5000;

  PageMethods.setText = function (e, t) {
    if (e.innerText != null) {
      e.innerText = t;
    }
  };

  // DevExpress loadingPane zIndex = 30000, HGO Framework ise 33333'ten başlatıyoruz...
  if (typeof (top.document.hgozIndex) === 'undefined' || typeof (top.document.hgozIndex) === null) {
    document.hgozIndex = 33333;
  }
  else {
    top.document.hgozIndex += 1;
    document.hgozIndex = top.document.hgozIndex;
  }

  if (typeof (top.document.hgoFrameIndex) === 'undefined' || typeof (top.document.hgoFrameIndex) === null) {
    top.document.hgoFrameIndex = 1;
  }


  // Ajax ve Js kütüphanelerinde kullanılıyor...
  PageMethods.getDocumentHeight = function () {
    return Math.max(
        Math.max(top.document.body.scrollHeight, top.document.documentElement.scrollHeight),
        Math.max(top.document.body.offsetHeight, top.document.documentElement.offsetHeight),
        Math.max(top.document.body.clientHeight, top.document.documentElement.clientHeight)
    );
  }


  // jQuery'nin Load edilip edilmediği tespit ediliyor...
  PageMethods.jQueryLoaded = (typeof (jQuery) != 'undefined');

  // Jquery login sayfasında kullanılmıyor...
  if (PageMethods.jQueryLoaded) {
    // Maksimum zIndex değerini veriyor...
    $.maxZIndex = $.fn.maxZIndex = function (opt) {
      var def = { inc: 1, group: "*" };
      $.extend(def, opt);
      var zmax = 0;
      $(def.group).each(function () {
        var cur = parseInt($(this).css('z-index'));
        zmax = cur > zmax ? cur : zmax;
      });
      if (!this.jquery)
        return zmax;

      return this.each(function () {
        zmax += def.inc;
        $(this).css("z-index", zmax);
      });
    }

    $.maxZIndexElement = $.fn.maxZIndexElement = function (opt) {
      var zmax = -1;
      var element = top.document.body;
      $('*').each(function () {
        var cur = parseInt($(this).css('z-index'));
        var curElement = $(this).get(0);

        if (cur > zmax)
          element = curElement;
      });

      return element;
    }

  }

  PageMethods.setInnerHtml = function (elementId, updateHtml, updateScript, scriptId) {
    document.getElementById(elementId).innerHTML = updateHtml;

    /* Mevcut Elementin altına ekleniyor. */
    if (updateScript != null && typeof (updateScript) != 'undefined') {
      var scriptElement = document.createElement("script");
      scriptElement.type = "text/javascript";
      scriptElement.id = scriptId;
      scriptElement.text = updateScript;
      document.getElementById(elementId).appendChild(scriptElement);
    }
  };


  PageMethods.createIFrame = function (frameName) {
    var frame = top.document.createElement("iframe");
    frame.name = frameName;
    frame.id = frameName;

    frame.style.width = "0px";
    frame.style.height = "0px";

    // for ie...
    frame.frameBorder = "0";
    frame.scrolling = "no";
    frame.marginHeight = "0px";
    frame.marginWidth = "0px";
    frame.style.border = 'none';

    top.document.hgoFrameIndex += 1;
    frame.style.left = (12 + (top.document.hgoFrameIndex * 3)).toString() + '%';
    frame.style.top = (22 + (top.document.hgoFrameIndex * 3)).toString() + '%';

    // Hidden...
    frame.style.display = "none";

    top.document.hgoFrameCount += 1;

    return frame;
  }

  PageMethods.getIFrameBody = function (frameName)
  {
    var frame = top.document.getElementById(frameName);
    var frameBody = null;

    if (frame.contentDocument) 
    {
      // Firefox...
      frameBody = frame.contentDocument.getElementsByTagName('body')[0];
    }
    else if (frame.contentWindow) 
    {
      // IE
      frameBody = frame.contentWindow.document.getElementsByTagName('body')[0];
    }

    return frameBody;
  }

  // Bu method sadece frame'i geri döndürür body içerisine ekleme yapmaz...
  PageMethods.getIFrameWindow = function (frameName)
  {
    var filterName = "#" + frameName;
    var iframe = $(filterName).get(0);

    if (!iframe)
      iframe = top.PageMethods.createIFrame(frameName);

    return iframe;
  }

  PageMethods.openModalWindow = function (url, frameName, width, height)
  {
    var modalBackground = null;
    var frame = null;

    if (top.document.getElementById('hgoModalBackGround' + frameName) == null)
    {
      modalBackground = top.document.createElement('div');
      modalBackground.id = 'hgoModalBackGround' + frameName;

      modalBackground.style.backgroundColor = '#D4D4D4';
      modalBackground.style.opacity = '0.5';
      modalBackground.style.filter = 'alpha(opacity=50)';
      modalBackground.style.position = 'absolute';
      top.document.hgozIndex += 1;
      modalBackground.style.zIndex = top.document.hgozIndex;
      modalBackground.style.top = '0px';
      modalBackground.style.left = '0px';
      modalBackground.style.width = '100%';
      modalBackground.style.height = '100%';
      modalBackground.style.display = 'none';

      // body'ye ekleniyor.
      top.document.body.appendChild(modalBackground);
    }
    else 
    {
      modalBackground = top.document.getElementById('hgoModalBackGround' + frameName);
      top.document.hgozIndex += 1;
      modalBackground.style.zIndex = top.document.hgozIndex;
    }

    // IFrame for URL...
    frame = top.PageMethods.getIFrameWindow("hgoModalWindow" + frameName);
    frame.style.backgroundColor = '#D4D4D4';

    // url veriliyor...
    frame.src = url;

    // for ie... 
    // // Gelen Html içerisindeki Body'yi değiştirmek daha düzgün load edilmesini sağlıyor.
    //frame.onload = function ()
    //{
    //  var frameBody = PageMethods.getIFrameBody('hgoModalWindow');
    //  frameBody.style.backgroundColor = '#D4D4D4';
    //}

    if (PageMethods.isIE || PageMethods.isOpera)
    {
      frame.style.width = (width + 4) + "px";   // 4 pixel tam border'ların görünmesi için ekleniyor...
      frame.style.height = (height + 4) + "px"; // 4 pixel tam border'ların görünmesi için ekleniyor...
    }
    else
    {
      frame.style.width = (width + 3) + "px";   // 3 pixel tam border'ların görünmesi için ekleniyor...
      frame.style.height = (height + 3) + "px"; // 3 pixel tam border'ların görünmesi için ekleniyor...
    }

    top.document.hgozIndex += 1;
    frame.style.zIndex = top.document.hgozIndex;
    frame.style.position = "absolute";
    frame.style.margin = "auto";

    top.document.body.appendChild(frame);

    // En son görünür yapılıyor.
    modalBackground.style.display = "inline";
    frame.style.display = "inline";
  }

  PageMethods.closeModalWindow = function (frameName) {

    top.document.hgoFrameIndex -= 1;

    var hgoModalBackground = $('#hgoModalBackGround' + frameName, top.document).get(0);
    if (hgoModalBackground != null) {
      var topBody = top.document.body;

      topBody.removeChild(hgoModalBackground);
    }

    var hgoModalWindow = $('#hgoModalWindow' + frameName, top.document).get(0);
    if (hgoModalWindow != null) {
      var topBody = top.document.body;

      // window "onUnload" event'inin tetiklenmesi için yapılıyor...
      hgoModalWindow.src = "about:blank";

      topBody.removeChild(hgoModalWindow);
    }
  }

  function AjaxObject () {
    // XmlHttpRequest oluşturuluyor.
    this.createAjaxRequest = function () {
      var xmlHttp = null;

      if (window.XMLHttpRequest)  // Mozilla, Safari...
      {
        xmlHttp = new XMLHttpRequest();
      }
      else if (window.ActiveXObject) // IE...
      {
        try {
          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {
          try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e) {
          }
        }
      }

      if (xmlHttp == null) {
        alert('Cannot create XML-HTTP-Request instance');
        return null;
      }

      return xmlHttp;
    };

    // Property...
    this.postUrl = window.location; 

    // Event...
    this.onSuccessfully = null;
    this.onError = null;
    this.onTimeOut = null;
    this.timeOutID = 0;
    this.defaultContentType = 'application/x-www-form-urlencoded; charset=UTF-8';

    this.timeOut = function (http_request) {
      // XmlHttpRequest bilgisi resetleniyor.
      if (http_request != null) {
        http_request.abort();
        http_request = null;
      };

      // Eğer timeOutID yok ise timeOut fonksiyonu tetiklenmemeli.
      if (this.timeOutID == 0)
        return;

      // timeOut Id bilgisi resetleniyor.
      clearTimeout(this.timeOutID);

      // Event tetikleniyor.
      if (this.onTimeOut != null)
        this.onTimeOut();

      this.onTimeOut = null;
    };

    this.isResultValue = false;
    this.responseJson = false;

    this.ajaxReceive = function (http_request) {
      // Ajax response received...
      if (http_request.readyState == 4) {
        if (http_request.status == 200) {
          // timeOut ID resetleniyor.
          clearTimeout(this.timeOutID);

          var resultstr = http_request.responseText;
          var responseHeader = http_request.getResponseHeader("Content-Type");

          this.isResultValue = (http_request.getResponseHeader("isResultValue") == "true");
          this.responseJson = (http_request.getResponseHeader("responseJson") == "true");
          this.resultValue = {};

          if ((typeof (responseHeader) != 'undefined') && (responseHeader != null)) {
            if (responseHeader.indexOf("text/html") != -1) {
              if (resultstr != "") {
                if (this.isResultValue)
                  this.resultValue = resultstr;

                // Gelen javascript kodu responseText'ten okunur ve
                // kod çalıştırılır.
                if (this.responseJson) {
                  this.JsonObject = 'undefined';
                  this.JsonObject = eval(resultstr);
                }
                else if (!this.isResultValue)
                  if (resultstr != "")
                    eval(resultstr);
              }
            }
            else {
              var frame = PageMethods.getIFrameWindow("receiveFile");
              document.body.appendChild(frame);

              frame.src = resultstr;
            }

            if (this.onSuccessfully != null)
              this.onSuccessfully(this.isResultValue, this.responseJson, this.resultValue, this.JsonObject);

            this.onSuccessfully = null;

            this.responseJson = false;
            this.resultValue = null;
          }
        }
        else {
          if (this.timeOut != null)
            this.timeOut(http_request);

          this.timeOut = null;
        }

        // XmlHttpRequest bilgisi gelen mesaj ile tekrar kullanılabileceğinden resetleniyor.
        if (http_request != null) {
          http_request.abort();
          http_request = null;
        }
      }
    };

    this._send = function (msgString) {
      try {
        this.http_request = this.createAjaxRequest();
        var url = this.postUrl;

        if (this.http_request != null) {
          this.http_request.open(PageMethods.formMethodType, url, true);

          // Set Header Info...
          this.http_request.setRequestHeader('Content-Type', this.defaultContentType);
          this.http_request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

          // isResultValue && responseJson...
          this.http_request.setRequestHeader('isResultValue', this.isResultValue);
          this.http_request.setRequestHeader('responseJson', this.responseJson);

          // Chrome'da uyarı mesajı veriyor... 
          //this.http_request.setRequestHeader("Content-length", msgString.length);
          //this.http_request.setRequestHeader('Connection', 'close');

          // When receive ajax, call procedure...
          var _this = this;
          this.http_request.onreadystatechange = function () { _this.ajaxReceive(_this.http_request) };
          this.timeOutID = setTimeout( function () { _this.timeOut(); }, PageMethods.timeOutDuration);

          this.http_request.send(msgString);

          // Default Values...
          this.isResultValue = false;
          this.responseJson = false;
        }
      }
      catch (e) {
        if (this.onError != null)
          this.onError(e.Message);

        this.onError = null;
      }
    };

    this.reqCount = 0;

    this.send = function (msgString) {
      this.reqCount++;
      this._send(msgString);
    };
  }

  PageMethods.createLoadingPane = function () {
    var blanket;
    var popup;
    var center;
    var img;
    var span;
    var label;
    var imgdiv;

    blanket = document.createElement('div');
    blanket.id = 'cloadingblanket';

    popup = document.createElement('div');
    popup.id = 'cloadingpopup';

    document.body.appendChild(blanket);
    document.body.appendChild(popup);

    center = document.createElement('center');
    center.id = 'cloadingcenter';
    center.style.marginLeft = '7px';
    popup.appendChild(center);

    imgdiv = document.createElement('div');
    imgdiv.id = 'cimgdiv';
    imgdiv.style.display = "block";

    // Cross Platform Çözüm
    imgdiv.style.styleFloat = 'left';
    imgdiv.style.float = 'left';
    imgdiv.style.cssFloat = 'left';

    imgdiv.style.marginLeft = "10px";

    img = document.createElement('img');
    img.id = 'cloadingimg';
    img.setAttribute('src', 'HGO.axd?file=ajaxloader2.gif');
    imgdiv.appendChild(img);
    center.appendChild(imgdiv);

    span = document.createElement('div');
    span.id = 'cloadingspan';

    // Cross Platform Çözüm
    span.style.styleFloat = 'left';
    span.style.float = 'left';
    span.style.cssFloat = 'left';

    span.style.display = "block";
    span.style.lineHeight = "30px";
    center.appendChild(span);

    label = document.createElement('h1');
    label.id = 'cloadinglabel';
    span.appendChild(label);

    blanket.style.backgroundColor = 'transparent';
    blanket.style.opacity = '0.75';
    blanket.style.filter = 'alpha(opacity=75)';
    blanket.style.position = 'absolute';

    var zIndexTemp = (document.hgozIndex + 1);
    blanket.style.zIndex = zIndexTemp.toString();
    blanket.style.top = '0px';
    blanket.style.left = '0px';
    blanket.style.width = '100%';
    blanket.style.height = PageMethods.getDocumentHeight() + "px";
    blanket.style.display = 'none';

    popup.style.position = 'absolute';
    popup.style.left = '45%';
    popup.style.top = '45%';
    popup.style.width = '150px';
    popup.style.height = '30px';

    var zIndexTemp = (document.hgozIndex + 1);
    popup.style.zIndex = zIndexTemp.toString();
    popup.style.border = '1px solid #585E68';
    popup.style.backgroundColor = 'white';

    img.style.marginTop = '5px';

    span.style.color = '#4D525B';
    span.style.paddingLeft = '8px';
    span.style.paddingRight = '3px';

    label.innerHTML = PageMethods.PleaseWaitStr;

    blanket.style.display = "none";
    popup.style.display = "none";
  }

  PageMethods.showLoadingPane = function () {
    var blanket;
    var popup;
    var center;
    var img;
    var span;
    var label;
    var imgdiv;

    blanket = document.getElementById('cloadingblanket');

    var blanketHeight = parseInt(blanket.style.height.split("px")[0]);
    var blanketHeight2 = PageMethods.getDocumentHeight();

    if (blanketHeight < blanketHeight2)
      blanket.style.height = blanketHeight2 + "px";

    popup = document.getElementById('cloadingpopup');

    center = document.getElementById('cloadingcenter');
    imgdiv = document.getElementById('cimgdiv');
    img = document.getElementById('cloadingimg');
    span = document.getElementById('cloadingspan');
    label = document.getElementById('cloadinglabel');

    label.innerHTML = PageMethods.PleaseWaitStr;

    blanket.style.display = "inline";
    popup.style.display = "inline";
  }

  PageMethods.hideLoadingPane = function ()
  {
    var blanket = document.getElementById('cloadingblanket');
    var popup = document.getElementById('cloadingpopup');

    if (blanket != null) 
    {
      blanket.style.display = "none";
      popup.style.display = "none";
    }
  }


 /* Copyright (c) 2007 	Josh Davis ( http://joshdavis.wordpress.com )
 * 
 * Licensed under the MIT License ( http://www.opensource.org/licenses/mit-license.php ) as follows:
 */

  /**
  * Binds a function to the given object's scope
  *
  * @param {Object} object The object to bind the function to.
  * @return {Function}	Returns the function bound to the object's scope.
  */
  Function.prototype.bind = function (object) {
    var method = this;
    return function () {
      return method.apply(object, arguments);
    };
  };

  /**
  * Create a new instance of Event.
  *
  * @classDescription	This class creates a new Event.
  * @return {Object}	Returns a new Event object.
  * @constructor
  */
  function Event() {
    this.events = [];
    this.builtinEvts = [];
  }

  /**
  * Gets the index of the given action for the element
  *
  * @memberOf Event
  * @param {Object} obj The element attached to the action.
  * @param {String} evt The name of the event.
  * @param {Function} action The action to execute upon the event firing.
  * @param {Object} binding The object to scope the action to.
  * @return {Number} Returns an integer.
  */
  Event.prototype.getActionIdx = function (obj, evt, action, binding) {
    if (obj && evt) {

      var curel = this.events[obj][evt];
      if (curel) {
        var len = curel.length;
        for (var i = len - 1; i >= 0; i--) {
          if (curel[i].action == action && curel[i].binding == binding) {
            return i;
          }
        }
      }
      else {
        return -1;
      }
    }
    return -1;
  };

  /**
  * Adds a listener
  *
  * @memberOf Event
  * @param {Object} obj The element attached to the action.
  * @param {String} evt The name of the event.
  * @param {Function} action The action to execute upon the event firing.
  * @param {Object} binding The object to scope the action to.
  * @return {null} Returns null.
  */
  Event.prototype.addListener = function (obj, evt, action, binding) {
    if (this.events[obj]) {
      if (this.events[obj][evt]) {
        if (this.getActionIdx(obj, evt, action, binding) == -1) {
          var curevt = this.events[obj][evt];
          curevt[curevt.length] = { action: action, binding: binding };
        }
      }
      else {
        this.events[obj][evt] = [];
        this.events[obj][evt][0] = { action: action, binding: binding };
      }
    }
    else {
      this.events[obj] = [];
      this.events[obj][evt] = [];
      this.events[obj][evt][0] = { action: action, binding: binding };
    }
  };

  /**
  * Removes a listener
  *
  * @memberOf Event
  * @param {Object} obj The element attached to the action.
  * @param {String} evt The name of the event.
  * @param {Function} action The action to execute upon the event firing.
  * @param {Object} binding The object to scope the action to.
  * @return {null} Returns null.
  */
  Event.prototype.removeListener = function (obj, evt, action, binding) {
    if (this.events[obj]) {
      if (this.events[obj][evt]) {
        var idx = this.actionExists(obj, evt, action, binding);
        if (idx >= 0) {
          this.events[obj][evt].splice(idx, 1);
        }
      }
    }
  };

  /**
  * Fires an event
  *
  * @memberOf Event
  * @param e [(event)] A builtin event passthrough
  * @param {Object} obj The element attached to the action.
  * @param {String} evt The name of the event.
  * @param {Object} args The argument attached to the event.
  * @return {null} Returns null.
  */
  Event.prototype.fireEvent = function (e, obj, evt, args) {
    if (!e) { e = window.event; }

    if (obj && this.events) {
      var evtel = this.events[obj];
      if (evtel) {
        var curel = evtel[evt];
        if (curel) {
          for (var act in curel) {
            var action = curel[act].action;
            if (curel[act].binding) {
              action = action.bind(curel[act].binding);
            }
            action(e, args);
          }
        }
      }
    }
  };
  /**
  * Checks for the existance of a builtin listener
  *
  * @memberOf Event
  * @param {Object} obj The element attached to the action.
  * @param {String} evt The name of the event.
  * @param {Function} action The action to execute upon the event firing.
  * @param {Object} binding The object to scope the action to.
  * @return {Object} Returns a builtin event object.
  */
  Event.prototype.getBuiltinListenerIdx = function (obj, evt, action, binding) {
    for (var i = this.builtinEvts.length - 1; i >= 0; i--) {
      var ArrayEl = this.builtinEvts[i];
      if (ArrayEl)
        if (ArrayEl.obj == obj && ArrayEl.evt == evt && ArrayEl.action == action && ArrayEl.binding == binding)
          return i;
    }
    return -1;
  };
  /**
  * Adds a builtin listener
  *
  * @memberOf Event
  * @param {Object} obj The element attached to the action.
  * @param {String} evt The name of the event.
  * @param {Function} action The action to execute upon the event firing.
  * @param {Object} binding The object to scope the action to.
  * @return {null} Returns null.
  */
  Event.prototype.addBuiltinListener = function (obj, evt, action, binding) {
    if (obj && evt && action) {
      if (this.getBuiltinListenerIdx(obj, evt, action, binding) < 0) {
        var boundAction = action;
        if (binding)
          boundAction = action.bind(binding);
        if (obj.addEventListener)
          obj.addEventListener(evt, boundAction, false);
        else if (obj.attachEvent)
          obj.attachEvent('on' + evt, boundAction);
        else
          obj['on' + evt] = boundAction;
        this.builtinEvts[this.builtinEvts.length] = { obj: obj, evt: evt, action: action, binding: binding, boundAction: boundAction };
      }
    }
  };
  /**
  * Removes a builtin listener
  *
  * @memberOf Event
  * @param {Object} obj The element attached to the action.
  * @param {String} evt The name of the event.
  * @param {Function} action The action to execute upon the event firing.
  * @param {Object} binding The object to scope the action to.
  * @return {null} Returns null.
  */
  Event.prototype.removeBuiltinListener = function (obj, evt, action, binding) {
    for (var i = this.builtinEvts.length - 1; i >= 0; i--) {
      var ArrayEl = this.builtinEvts[i];
      if (ArrayEl) {
        if (obj && evt && action && binding)
          if (ArrayEl.obj == obj && ArrayEl.evt == evt && ArrayEl.action == action && ArrayEl.binding == binding) {
            this.detachListener(ArrayEl, i);
            break;
          }
          else if (obj && evt && action)
            if (ArrayEl.obj == obj && ArrayEl.evt == evt && ArrayEl.action == action)
              this.detachListener(ArrayEl, i);
            else if (obj && evt)
              if (ArrayEl.obj == obj && ArrayEl.evt == evt)
                this.detachListener(ArrayEl, i);
              else if (obj)
                if (ArrayEl.obj == obj)
                  this.detachListener(ArrayEl, i);
                else
                  this.detachListener(ArrayEl, i);
      }
    }
  };
  /**
  * Detaches a builtin listener from a DOM object (prevents memory leaks)
  *
  * @memberOf Event
  * @param {Object} arrayEl The builtin listener object.
  * @param {Number} idx The index of the object in the builtin listener array.
  * @return {null} Returns null.
  */
  Event.prototype.detachListener = function (arrayEl, idx) {
    var obj = arrayEl.obj;
    var evt = arrayEl.evt;
    var boundAction = arrayEl.boundAction;

    if (obj.removeEventListener)
      obj.removeEventListener(evt, boundAction, false);
    evt = 'on' + evt;
    if (obj.detachEvent)
      obj.detachEvent(evt, boundAction);
    obj[evt] = null;

    delete arrayEl.obj;
    delete arrayEl.evt;
    delete arrayEl.action;
    delete arrayEl.binding;
    delete arrayEl.boundAction;

    delete this.builtinEvts[idx];
    this.builtinEvts.splice(idx, 1);
  };


var gEVENTS = new Event();

function DeleteNode(node) {
  if(node) //make sure the node exists
  {
    DeleteChildren(node); //delete node's children

    gEVENTS.removeBuiltinListener(node); //remove listeners

    if (typeof node.outerHTML !== 'undefined') {
      try
      {
        node.outerHTML = ''; //prevent pseudo-leak in IE or Chrome Last version...
      }
      catch(err) {
        // herhangi bir işleme gerek yok...
      }
    }
    else
      if (node.parentNode) //if the node has a parent
        node.parentNode.removeChild(node);  //remove the node from the DOM tree

    delete node; //clean up just to be sure
  }
}

function DeleteChildren(node) {
  if (node) //make sure the node exists
  {
    for (var x = node.childNodes.length - 1; x >= 0; x--) //delete all of node's children
    {
      var childNode = node.childNodes[x];

      if (childNode.hasChildNodes()) //if the child node has children then delete them first
        DeleteChildren(childNode);

      gEVENTS.removeBuiltinListener(childNode); //remove listeners

      if (typeof childNode.outerHTML !== 'undefined') {
        try {
          childNode.outerHTML = ''; //prevent pseudo-leak in IE or Chrome Last version...
        }
        catch (err) {
          // herhangi bir işleme gerek yok...
        }
      }
      else
        node.removeChild(childNode);  //remove the child from the DOM tree

      delete childNode; //clean up just to be sure
    }
  }
}


